package com.huaao.micropolice.core.model.system;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import com.huaao.micropolice.common.util.Encodes;

/**
 * @author qiyang
 * 用户
 * @version 1.0
 */
public class User implements Serializable{
	private String id;
	private String code;
	private String realname;
	private String username;
	private String password;
	private String rawPassword;
	private String sex;
	private String phone;
	private String email;
	private String salt;
	
	private Dept dept;
	private Jobs jobs;
	private Date lastLoginTime;
	private Date lastLoginOutTime;
	
	private Set<Role> roles = new LinkedHashSet<Role>();
	
	public User(){}
	
	public User(String id , String username){
		this.id = id;
		this.username = username;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getRealname() {
		return realname;
	}
	public void setRealname(String realname) {
		this.realname = realname;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Dept getDept() {
		return dept;
	}
	public void setDept(Dept dept) {
		this.dept = dept;
	}
	public Jobs getJobs() {
		return jobs;
	}
	public void setJobs(Jobs jobs) {
		this.jobs = jobs;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Date getLastLoginTime() {
		return lastLoginTime;
	}
	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}
	public Date getLastLoginOutTime() {
		return lastLoginOutTime;
	}
	public void setLastLoginOutTime(Date lastLoginOutTime) {
		this.lastLoginOutTime = lastLoginOutTime;
	}
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	public String getDeptId(){
		if(this.dept != null){
			return dept.getId();
		}
		return null;
	}
	public String getDeptName(){
		if(this.dept != null){
			return dept.getName();
		}
		return null;
	}
	public void setDeptId(String deptId){
		Dept obj = new Dept();
		obj.setId(deptId);
		this.setDept(obj);
	}
	public String getRawPassword() {
		return rawPassword;
	}
	public void setRawPassword(String rawPassword) {
		this.rawPassword = rawPassword;
	}
	public String getSalt() {
		return salt;
	}
	public void setSalt(String salt) {
		this.salt = salt;
	}

	public byte[] getSaltBytes() {
		String salt = getSalt();
		if (StringUtils.isNotBlank(salt)) {
			return Encodes.decodeHex(salt);
		} else {
			return null;
		}
	}
	
	
}
